package com.lsh.oms.provider.service.endpoint;

import com.alibaba.dubbo.config.annotation.Service;
import com.lsh.base.lang.Maps;
import com.lsh.oms.core.records.core.RefundRepository;

import javax.annotation.Resource;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Map;

@Path("refunds")
@Service(protocol = "rest", timeout = 30000)
public class RefundsResource implements com.lsh.oms.api.endpoint.core.RefundsResource {

    @Resource
    private RefundRepository refunds;

    @POST
    @Path("{id}/apportion")
    @Consumes({MediaType.APPLICATION_JSON})
    @Produces({MediaType.APPLICATION_JSON})
    @Override
    public Response apportion(@PathParam("id") Long id, Map<String, Object> request) {
        boolean affected = refunds.apportion(id, request);
        return Response.ok(Maps.of("affected", affected)).build();
    }
}
